﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TheatreManagementSystem
{
    public class Ticket : IPrintable
    {
        string uniqueIdentifier;
        Play play;
        DateTime time;
        Seat seat;
        string hallName;
        string customerName;
        decimal price;

        public string UniqueIdentifier
        {
            get { return uniqueIdentifier; }
        }

        public Play Play
        {
            get { return play; }
        }

        public DateTime Time
        {
            get { return time; }
        }

        public Seat Seat
        {
            get { return seat; }
        }

        public string HallName
        {
            get { return hallName; }
        }

        public string CustomerName
        {
            get { return customerName; }
        }

        public decimal Price
        {
            get { return price; }
        }

        public Ticket(string uniqueIdentifier, Play play, DateTime time, Seat seat, string hallName, decimal price)
            :this(uniqueIdentifier, play, time, seat, hallName, price, null)
        {
        }

        public Ticket(string uniqueIdentifier, Play play, DateTime time, Seat seat, string hallName, decimal price, string customerName)
        {
            this.uniqueIdentifier = uniqueIdentifier;
            this.play = play;
            this.time = time;
            this.seat = seat;
            this.hallName = hallName;
            this.customerName = customerName;
            this.price = price;
        }

        public string PrepareForPrint()
        {
            const int ticketWidth = 50;
            StringBuilder print = new StringBuilder();
            print.AppendLine(new string('*', ticketWidth));
            print.AppendLine("*" + new string(' ', ticketWidth - 2) + "*");
            print.AppendLine("*" + new string(' ', ticketWidth - 2) + "*");
            print.AppendLine("*" + new string(' ', ticketWidth - 2) + "*");
            print.AppendLine("*" + new string(' ', 5) + this.play + new string(' ', ticketWidth - 5 - 2 - this.Play.ToString().Length) + "*");
            print.AppendLine("*" + new string(' ', 5) + this.time.ToString() + new string(' ', ticketWidth - this.Time.ToString().Length - 5 - 2) + "*");
            print.AppendLine("*" + new string(' ', 5) + this.HallName.ToString() + new string(' ', ticketWidth - this.HallName.Length - 5 - 2) + "*");
            string seatnum = String.Format("Row: {0}, Seat: {1}", this.Seat.Rows, this.Seat.Cols);
            print.AppendLine("*" + new string(' ', 5) + seatnum.ToString() + new string(' ', ticketWidth - seatnum.Length - 5 - 2) + "*");
            if (this.CustomerName != null)
            {
                print.AppendLine("*" + new string(' ', 5) + this.customerName + new string(' ', ticketWidth - this.customerName.Length - 5 - 2) + "*");
            }
            else
            {
                print.AppendLine("*" + new string(' ', ticketWidth - 2) + "*");
            }
            print.AppendLine("*" + new string(' ', 5) + price.ToString() + new string(' ', ticketWidth - price.ToString().Length - 5 - 2) + "*");
            print.AppendLine("*" + new string(' ', ticketWidth - 2) + "*");
            print.AppendLine("*" + new string(' ', ticketWidth - 2) + "*");
            print.AppendLine("* " + this.UniqueIdentifier + new string(' ', ticketWidth - this.UniqueIdentifier.Length - 3) + "*");
            print.AppendLine(new string('*', ticketWidth));
            return print.ToString();
        }
    }
}
